package com.wwwarehouse.usercenter.fragment.business_relationship;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CardDeskFunctionResponseBean;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.constant.UserCenterConstant;

/**
 * Created by xiaoke.ni on 2017/11/3.
 */

@Route(path = UserCenterConstant.PATH_AUTHORITY_BR_ADD_FRIENDS)
public class BRAddFriendsSelectRelationFragment extends BaseFragment implements View.OnClickListener {

    private View mView;
    private Button mSupplierBtn;
    private Button mCustomerBtn;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = View.inflate(getActivity(), R.layout.fragment_br_add_friends_select_relation, null);
        return mView;
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof BRAddFriendsSelectRelationFragment) {
            mActivity.setTitle(getString(R.string.user_br_add_friends));
        }
    }

    @Override
    public void requestDatas() {
        initView();

    }

    private void initView() {
        mSupplierBtn = (Button) mView.findViewById(R.id.supplier_btn);
        mCustomerBtn = (Button) mView.findViewById(R.id.customer_btn);

        mSupplierBtn.setOnClickListener(this);
        mCustomerBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.supplier_btn) {
            CardDeskFunctionResponseBean.TaskBean taskBean = (CardDeskFunctionResponseBean.TaskBean) getArguments().getSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS);
            BRAddFriendsFragment friendsFragment = new BRAddFriendsFragment();
            Bundle bundle = new Bundle();
            bundle.putString("buId", taskBean.getBusinessId());
            bundle.putString("taskTypeUkid", taskBean.getTaskTypeUkid());
            bundle.putString("relationType", "SUPPLIER");
            friendsFragment.setArguments(bundle);
            pushFragment(friendsFragment);
        } else if (id == R.id.customer_btn) {
            CardDeskFunctionResponseBean.TaskBean taskBean = (CardDeskFunctionResponseBean.TaskBean) getArguments().getSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS);
            BRAddFriendsFragment friendsFragment = new BRAddFriendsFragment();
            Bundle bundle = new Bundle();
            bundle.putString("buId", taskBean.getBusinessId());
            bundle.putString("taskTypeUkid", taskBean.getTaskTypeUkid());
            bundle.putString("relationType", "CUSTOMER");
            friendsFragment.setArguments(bundle);
            pushFragment(friendsFragment);
        }

    }
}
